﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace _4Gewinnt
{
    /// <summary>
    /// Select the enines for a single match
    /// </summary>
    public partial class SelectEnginesOneGame_GUI : Form
    {
        /// <summary>
        /// The selected red player
        /// </summary>
        public Engine redPlayer;
        /// <summary>
        /// The selected blue player
        /// </summary>
        public Engine bluePlayer;

        /// <summary>
        /// Initialize the dialog
        /// </summary>
        public SelectEnginesOneGame_GUI(Type[] engines)
        {
            InitializeComponent();

            //put the engines into the listbox
            listBoxBluePlayer.DataSource = engines.ToArray(); //make a copy of engines
            listBoxRedPlayer.DataSource = engines;
            listBoxBluePlayer.DisplayMember = "Name";
            listBoxRedPlayer.DisplayMember = "Name";

            listBoxRedPlayer.SelectedIndex = 0;
            listBoxBluePlayer.SelectedIndex = 0;
        }


        /// <summary>
        /// Create new engine objects according to the selections
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonOk_Click(object sender, EventArgs e)
        {
            redPlayer = Engine.Create((Type)listBoxRedPlayer.SelectedItem, GameColor.Red);
            bluePlayer = Engine.Create((Type)listBoxBluePlayer.SelectedItem, GameColor.Blue);
            
            if (redPlayer != null && bluePlayer != null)
                this.Close();
        }


    }
}
